function Page() { };
Page.prototype.initPage = function () {
    $("#info").height(($(window).height() - 112));
    $("#searchResult").css("bottom", ($(window).height() - 189));
    $("#leftBall").click(function () {
        if (modelBussiness.RouteState == 1) {
            layer.msg("正在执行巡检！");
            return;
        }
        if (modelBussiness && modelBussiness.backBtn) {
            modelBussiness.backBtn();
        }
    });
    $("#searchBtn").click(function () {

        if (parseInt($("#searchInfo").css("right")) < -10) {
            $("#searchInfo").animate({ "right": "1" }, 1);
            $("#searchInfo").show();
        } else {
            $("#searchResult").animate({ "height": "0", "bottom": ($(window).height() - 209) }, 500);
            setTimeout(function () {
                $("#searchInfo").hide();
                $("#searchResult").hide();
                $("#searchInfo").animate({ "right": "-500" }, 500);
            }, 500);
        }


    });
    $("#btn1").click(function () {
        if (parseInt($("#searchInfo").css("right")) < -10) {
            $("#searchInfo").animate({ "right": "1" }, 1);
            $("#searchInfo").show();
        } else {
            $("#searchResult").animate({ "height": "0", "bottom": ($(window).height() - 189) }, 500);
            setTimeout(function () {
                $("#searchInfo").hide();
                $("#searchResult").hide();
                $("#searchInfo").animate({ "right": "-500" }, 500);
                $("#searchResult").animate({ "right": "-500" }, 500);
            }, 500);
        }
    });
    $("#btn5").click(function () {
        layer.msg("wait..");
    });
    this.bindLeftBtns();
    this.flashAlarmBtn();
    $("html").css("background", "none");
    if (roomConfig && roomConfig.background) {
        $("body").css("background", roomConfig.background)
    }
};
//左侧按钮绑定
Page.prototype.bindLeftBtns = function () {
    var _this = this;
    var enables = webapi.getEnables();
    var html = "";
    var btnnubs = 0;
	console.log('enables',enables)
    if (enables.alarm) {
        btnnubs++;
        html += `<div class="toolbarDiv" id="div_btn_1">
            <img class="toolbarImg" src="../img/pageimg2/ycsb.png" title="告警监控" id="btn_1"
                 data_sort="0" data_btntype="system" data_enable="true">
            <div class="toolbarTitle" id="title_btn_1">告警监控</div>
        </div>`;
    } else {
        modelBussiness.flashAlarm = false;
       
    }
    if (enables.space) {
        btnnubs++;
        html += ` <div class="toolbarDiv" id="div_btn_2">
            <img class="toolbarImg" src="../img/pageimg2/kjlyl.png" title="空间" id="btn_2"
                 data_sort="0" data_btntype="system" data_enable="true">
            <div class="toolbarTitle" id="title_btn_2">空间</div>
        </div>`;
    }
    if (enables.uUse) {
        btnnubs++;
        html += `<div class="toolbarDiv" id="div_btn_3">
            <img class="toolbarImg" src="../img/pageimg2/up.png" title="U位" id="btn_7"
                 data_sort="0" data_btntype="system" data_enable="true">
            <div class="toolbarTitle" id="title_btn_3">U位</div>
        </div>`;
    }
    if (enables.temp) {
        btnnubs++;
        html += `<div class="toolbarDiv" id="div_btn_4">
            <img class="toolbarImg" src="../img/pageimg2/wdj.png" title="温度" id="btn_3"
                 data_sort="0" data_btntype="system" data_enable="true">
            <div class="toolbarTitle" id="title_btn_4">温度</div>
        </div>`;
    }
    if (enables.bearing) {
        btnnubs++;
        html += ` <div class="toolbarDiv" id="div_btn_5">
            <img class="toolbarImg" src="../img/pageimg2/zl.png" title="承重" id="btn_5"
                 data_sort="0" data_btntype="system" data_enable="true">
            <div class="toolbarTitle" id="title_btn_5">承重</div>
        </div>`;
    }
    if (enables.energy) {
        btnnubs++;
        html += ` <div class="toolbarDiv" id="div_btn_6">
            <img class="toolbarImg" src="../img/pageimg2/gh2.png" title="功耗" id="btn_4"
                 data_sort="0" data_btntype="system" data_enable="true">
            <div class="toolbarTitle" id="title_btn_6">功耗</div>
        </div>`;
    }
    $("#toolbar").html(html);
    if (btnnubs == 0) {
        $("#toolbar").hide();
    } else {
        $("#toolbar").height(btnnubs * 97 - 2);
    }
    if (enables.energy) {
        html += ` <div class="toolbarDiv" id="div_btn_6">
            <img class="toolbarImg" src="../img/pageimg2/gh2.png" title="功耗" id="btn_4"
                 data_sort="0" data_btntype="system" data_enable="true">
            <div class="toolbarTitle" id="title_btn_6">功耗</div>
        </div>`;
    }
    if (enables.search) {
        $("#btn1").show();
    } else {
        $("#btn1").hide();
    }
    $(".toolbarDiv").click(function () {
        if (modelBussiness.RouteState == 1) {
            layer.msg("正在执行巡检！");
            return;
        }
        var id = $(this).attr("id");


   

        switch (id) {
            case "div_btn_1"://异常设备
                {
                    clearInterval(_this.alarmSetintervalIndex);
                    $("#btn_1").fadeTo(100, 1);
                    if ($("#btn_1").attr("title") == "告警监控") {
                        $("#btn_1").attr("title", "关闭告警闪动");
                        $("#btn_1").attr("src", "../img/pageimg2/ycsbclose.png");
                        modelBussiness.closeAlarm();
                    } else {
                        _this.flashAlarmBtn();
                        modelBussiness.startAlarm();
                        $("#btn_1").attr("src", "../img/pageimg2/ycsb.png");
                        $("#btn_1").attr("title", "告警监控");
                    }
                }
                break;
            case "div_btn_2"://空间
                {
                    modelBussiness.currentState = 22;
                    modelBussiness.showSpaceRate();
                }
                break;
            case "div_btn_3"://U位
                {
                    modelBussiness.currentState = 23;
                    modelBussiness.showUsageMap();
                }
            
                break;
            case "div_btn_4":
                {
              
                    modelBussiness.currentState = 24;
                    modelBussiness.showTemptureMap();
                }//温度
                
                break;
            case "div_btn_5"://承重
                {
                    modelBussiness.currentState = 25;
                    modelBussiness.showBearing();
                }
                break;
            case "div_btn_6"://功率
                {
                    modelBussiness.currentState = 26;
                    modelBussiness.showEnergyRate();
                }
                break;

        }
    });
}

Page.prototype.flashAlarmBtn = function () {
    var _this = this;
    _this.status = 1;
    _this.alarmSetintervalIndex = setInterval(function () {
        $("#btn_1").fadeTo(900, _this.status);
        if (_this.status == 1) {
            _this.status = 0.5;
        } else {
            _this.status = 1;
        }
    }, 1000);
}
Page.prototype.normalTrangle = 0;
//浮球
Page.prototype.transLeftBall = function (value) {
    this.normalTrangle += (value);
    $("#leftBall").css("transform", "rotate(" + this.normalTrangle + "deg)");
} 
//搜索
Page.prototype.Search = function () {
    //$("#searchResult").animate({ "right": "1" }, 500);
    $("#searchResult").css("right", "1px");
    $("#searchResult").animate({ "height": ($(window).height() - 159), "bottom": 2 }, 500);
    var keyWord = $("#txt_search_keyWord").val();
    keyWord = $.trim(keyWord);
    if(!keyWord || keyWord == ''){
        layer.msg("请输入机柜名称！")
        return
    }

    var loadindex=layer.load();
    webapi.getSearchInfos(keyWord, function (data) {
        layer.close(loadindex);
        var resultNubs = Math.random() * 10 + 1;
        var shownub = 0;
        if (data && data.length > 0) {
            var resultStr = "";
            $.each(data, function (_index, _obj) {
                if (_index < resultNubs) {
                    shownub++;
                    resultStr += "<tr class='resultTr' data-index='" + _index + "' class='trSelect' style='cursor:pointer;'><td style='width:10%'>" + (_index + 1) + "</td><td  style='width:40%'>" + _obj.serverBrand + "</td><td style='width:30%'>" + _obj.serverType + "</td><td><div onclick=\"modelBussiness.showPosition('" + _obj.cabId + "','" + _obj.id + "')\" class='btn_dw'>定位</div></td></tr>";
                }
            });
            $("#searchResultContent").html("<table class='table'><tbody>"+ resultStr + " </tbody></table >");
        } else {
            $("#searchResultContent").html("<span style=' font-size: 16px;color: #ffbe00;margin-top:50px;'>查无结果！</span>");
        }

        $("#searchResult").show();
        $("#searchResult").show();
        $("#searchResult").animate({ "height": ($(window).height() - 159), "bottom": 0 }, 500);
        $("#searchResultContent").height($(window).height() - 209);


    });
  
}
var pageindex = null;